package com.rockxin.cat.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.rockxin.cat.R;
import com.rockxin.cat.adapter.PagerAdapter;
import com.rockxin.cat.base.BaseActivity;
import com.rockxin.cat.customview.NoScrollViewPager;
import com.rockxin.cat.fragment.RecommendAwardFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 推荐奖励
 */
public class RecommendAwardActivity extends BaseActivity {

    @BindView(R.id.back_img)
    ImageView backImg;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.myInvite)
    TextView myInvite;
    @BindView(R.id.inviteInvest)
    TextView inviteInvest;
    @BindView(R.id.noInvest)
    TextView noInvest;
    @BindView(R.id.viewPager)
    NoScrollViewPager viewPager;

    private RecommendAwardActivity mRecommendAwardActivity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mRecommendAwardActivity = this;
    }

    @Override
    protected int setLayout() {
        return R.layout.activity_recommend_award;
    }

    @Override
    public void initData() {
        title.setText("推荐奖励");
        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(RecommendAwardFragment.newInstance(2));
        fragmentList.add(RecommendAwardFragment.newInstance(0));
        fragmentList.add(RecommendAwardFragment.newInstance(1));
        viewPager.setAdapter(new PagerAdapter(getSupportFragmentManager(), fragmentList));
        viewPager.setOffscreenPageLimit(fragmentList.size());
        viewPager.setNoScroll(true);
        viewPager.setCurrentItem(0);

    }

    @OnClick({R.id.back_img, R.id.myInvite, R.id.inviteInvest, R.id.noInvest})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_img:
                finish();
                break;
            case R.id.myInvite:
                setDefaultState();
                myInvite.setTextColor(ContextCompat.getColor(mRecommendAwardActivity, R.color.colorMoney));
                viewPager.setCurrentItem(0);
                break;
            case R.id.inviteInvest:
                setDefaultState();
                inviteInvest.setTextColor(ContextCompat.getColor(mRecommendAwardActivity, R.color.colorMoney));
                viewPager.setCurrentItem(1);

                break;
            case R.id.noInvest:
                setDefaultState();
                noInvest.setTextColor(ContextCompat.getColor(mRecommendAwardActivity, R.color.colorMoney));
                viewPager.setCurrentItem(2);
                break;
        }
    }

    private void setDefaultState() {
        myInvite.setTextColor(ContextCompat.getColor(mRecommendAwardActivity, R.color.colorTextColor));
        inviteInvest.setTextColor(ContextCompat.getColor(mRecommendAwardActivity, R.color.colorTextColor));
        noInvest.setTextColor(ContextCompat.getColor(mRecommendAwardActivity, R.color.colorTextColor));
    }
}
